package org.demo.base.proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {

    private Object targect;

    public ProxyFactory(Object targect) {
        this.targect = targect;
    }

    public Object getPorxyInstance(){
        Object instance = Proxy.newProxyInstance(targect.getClass().getClassLoader(), targect.getClass().getInterfaces(), new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("执行前。。。");
                Object returnValue = method.invoke(targect, args);
                System.out.println("执行后。。。");
                return returnValue;
            }
        });
        return instance;
    }
}
